<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Current URL
 *
 * Returns the full URL (including segments) of the page where this
 * function is placed
 *
 * @access	public
 * @return	string
 */
if ( ! function_exists('current_url'))
{
	function current_url($js = FALSE)
	{
		$CI =& get_instance();
		$get = "";
		foreach($_GET as $key => $val) {
			$get .= (($get)?("&".(($js)?(""):("")).$key."=".$val):("?".$key."=".$val));
		}
		return $CI->config->site_url($CI->uri->uri_string()).$get;
	}
}

/**
 * Anchor Link
 *
 * Creates an anchor based on the local URL.
 *
 * @access	public
 * @param	string	the URL
 * @param	string	the link title
 * @param	mixed	any attributes
 * @return	string
 */
if ( ! function_exists('anchor'))
{
	function anchor($uri = '', $title = '', $attributes = '', $forced = FALSE)
	{
		$title = (string) $title;
		
		// study-abroad force
		if(!$forced) {
			$CI =& get_instance();
			$CI->load->model("continent");
			$getContinent = $CI->continent->getContinent();
			$arrUri = explode("/", $uri);
			$firstUri = $arrUri[0];
			foreach($getContinent as $con) {
				if($firstUri == $con["conUrlName"]) {
					$uri = "study-abroad/".$uri;
				}
			}
		}
		
		if($forced) {
			$CI =& get_instance();
			$tmpuri = "";
			if(in_array($CI->uri->segment(1), array("study-abroad", "summer-study"))) {
				$tmpuri = $CI->uri->segment(1)."/";
			}
			if(in_array($CI->uri->segment(2), $CI->config->item("study-abroad-programs"))) {
				$tmpuri = "study-abroad/".$CI->uri->segment(2)."/";
			}
			$uri = $tmpuri.$uri;
		}

		if ( ! is_array($uri))
		{
			$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
		}
		else
		{
			$site_url = site_url($uri);
		}

		if ($title == '')
		{
			$title = $site_url;
		}

		if ($attributes != '')
		{
			$attributes = _parse_attributes($attributes);
		}

		return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
	}
}

function my_url_title($str, $separator = 'dash', $lowercase = FALSE) {
	return url_title(str_replace(array("á", "é", "í", "ö", "ü", "ó", "ő", "ú", "ű"), array("a", "e", "i", "o", "u", "o", "o", "u", "u"), mb_strtolower($str)), $separator, $lowercase);
}